<?php
class Admin extends CI_Controller {
	function __construct() {
		parent::__construct();
		$this->load->model('volunteer_model');
	}

	function index($err = '') {
		$this->load->view('admin_login');
	}
	
	function home() {
		if($this->session->userdata('vol_id') == FALSE) {
			redirect('admin/index/login_timeout', 'refresh');
		}
		$data['uid'] = $this->session->userdata('uid');
		$data['pos'] = $this->session->userdata('pos');
		$data['name'] = $this->session->userdata('name');
		$data['module'] = '';
		$this->load->view('admin_home',$data);
	}

	function login() {
		$uid = $this->input->post('uid');
		$pswd = $this->input->post('pswd');
		$res = $this->volunteer_model->login($uid, $pswd);
		if($res == 0) {
			redirect('admin/index/name_pswd_error', 'refresh');
		}
		elseif($res == -1) {
			redirect('admin/index/login_fail', 'refresh');
		}
		else {
			$detail = $this->volunteer_model->get_vol_detail($res);
			$this->session->set_userdata('vol_id', $res);
			$this->session->set_userdata('uid', $uid);
			$this->session->set_userdata('name', $detail['name']);
			$this->session->set_userdata('pos', $detail['position']);
			redirect('admin/home', 'refresh');
		}			
	}

	function logout() {
		$this->session->sess_destroy();
		redirect('admin/', 'refresh');
	}

}
/* End of file admin.php*/